#include "timer_bsp.h"


static void led_test(void)
{

}

static const WHT_Timer_Basic_Config_t Basic_config[] = 
{
    {
    .PreemptionPriority = 15,
    .SubPriority =0,
    .Interrupt_Callback = led_test,
    }
};

static const WHT_Timer_PWM_Out_Config_t PWM_config[] =
{
    {
        .Channel = Timer_CH3,
        .Normal_Polarity = Hig,
        .Normal_Idle_Polarity = Low,
        .Normal_Output_GPIO_Port = PortA,
        .Normal_Output_GPIO_Pin = Pin10,

        .Complementary_Output_State = ENABLE,
        .CO_Polarity = Low,
        .CO_Idle_Polarity = Low,
        .CO_Output_GPIO_Port = PortB,
        .CO_Output_GPIO_Pin = Pin15,

        .Brake_Output_State = ENABLE,
        .Brake_Output_GPIO_Port = PortB,
        .Brake_Output_GPIO_Pin = Pin12,
    },
    {
        .Channel = Timer_CH2,
        .Normal_Polarity = Hig,
        .Normal_Idle_Polarity = Low,
        .Normal_Output_GPIO_Port = PortA,
        .Normal_Output_GPIO_Pin = Pin9,

        .Complementary_Output_State = ENABLE,
        .CO_Polarity = Low,
        .CO_Idle_Polarity = Low,
        .CO_Output_GPIO_Port = PortB,
        .CO_Output_GPIO_Pin = Pin14,

        .Brake_Output_State = DISABLE,
        .Brake_Output_GPIO_Port = PortB,
        .Brake_Output_GPIO_Pin = Pin12,
    },
    {
        .Channel = Timer_CH1,
        .Normal_Polarity = Low,
        .Normal_Idle_Polarity = Low,
        .Normal_Output_GPIO_Port = PortA,
        .Normal_Output_GPIO_Pin = Pin8,

        .Complementary_Output_State = ENABLE,
        .CO_Polarity = Low,
        .CO_Idle_Polarity = Low,
        .CO_Output_GPIO_Port = PortB,
        .CO_Output_GPIO_Pin = Pin13,

        .Brake_Output_State = DISABLE,
        .Brake_Output_GPIO_Port = PortB,
        .Brake_Output_GPIO_Pin = Pin12,
    },
};


static WHT_Timer_Config_t timer_config =
{
    .Name = Timer1,
    .Cycle_ns = 1000000,
    .Mode = Timer_Output_Comparison,
    /////.Mode = Timer_Basic,
    .Config_Count = 3,
    .Config = &PWM_config,
    ////.Config = &Basic_config,
};



void timer_test(void)
{
    WHT_Timer_BSP.WHT_Config(&timer_config);
    
    WHT_Timer_BSP.WHT_Set_Duty_Cycle(&timer_config, PWM_config[0].Channel, 50.0f);
    WHT_Timer_BSP.WHT_Set_Duty_Cycle(&timer_config, PWM_config[1].Channel, 50.0f);
    WHT_Timer_BSP.WHT_Set_Duty_Cycle(&timer_config, PWM_config[2].Channel, 50.0f);
    WHT_Timer_BSP.WHT_Start(&timer_config);


    if(0)
    {
        WHT_Timer_BSP.WHT_Stop(&timer_config);
    }
    else
    {
        WHT_Timer_BSP.WHT_Start(&timer_config);
    }    
}

